package top.stmo.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.stmo.dao.BooksDao;
import top.stmo.exception.BusinessException;
import top.stmo.pojo.Books;
import top.stmo.service.BooksService;
import top.stmo.vo.Code;

import java.util.List;

@Service
public class BooksServiceImpl implements BooksService {

    @Autowired
    private BooksDao booksDao;

    public boolean save(Books books) {
        boolean b = booksDao.save(books);
        return b;
    }

    @Override
    public List<Books> getAll() {
        List<Books> booksList = booksDao.getAll();
        return booksList;
    }

    @Override
    public Books getById(Integer id) {

        if (id == 1) {
            throw new BusinessException(Code.SYSTEM_ERR,"业务异常，请勿进行非法操作");
        }
//
//        try {
//            int i = 1/0;
//        }catch (Exception e) {
//            throw new SystemException(Code.SYSTEM_TIMEOUT_ERR,"服务器超时");
//        }

        Books books = booksDao.getById(id);
        return books;
    }

    @Override
    public boolean delete(Integer id) {
        boolean b = booksDao.delete(id);
        return b;
    }

    @Override
    public boolean update(Books books) {
        boolean b = booksDao.update(books);
        return b;
    }


}
